function GetQueryString(name)
{
 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
 var r = window.location.search.substr(1).match(reg);
 if(r!=null)return  unescape(r[2]); return null;
}

function getAllblogs() {
		var pageCount= GetQueryString("pageCount") ;
	 	function delHtmlTag(str){
		  return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
		 }
		$.ajax({
		type:"POST",		
		url:"blog_requestAllBlogs.action",
		data:{page:pageCount == undefined?1:pageCount,limit:4},
		success:function(result) {
							var data = result.data.list;
							var i = 0;
							var length=data.length;
							setPageParam(result.data);
							for (i = 0; i < length; i++) {
								var article = $("<article class='post post-1'></article>");
								article.appendTo($("#bloglist"));
								var header =$("<header class='entry-header'></header>");
								header.appendTo(article);
								var h1=$("<h1 class='entry-title'></h1>");
								var title = $("<a href='single.html?id="+data[i].id+"'>"+data[i].title+"</a>");
								title.appendTo(h1);
								h1.appendTo(header);
								var metaDiv=$("<div class='entry-meta'></div>");
								metaDiv.appendTo(header);
								var kind = $("<span class='post-category'><a>" + data[i].kind
										+ "<a/></span>");
								kind.appendTo(metaDiv);
								var date=$("<span class='post-date'>" 
										+ "</span>");
								var pubdate = $("<a><time class='entry-date' datetime='"+data[i].pubdate+"''>"
										+ data[i].pubdate + "</time></a>");
								pubdate.appendTo(date);
								date.appendTo(metaDiv);

								var author = $("<span class='post-author'><a>" 
										+ data[i].author + "<a></span>");
								author.appendTo(metaDiv);
								 var Comments=$("<span class='comments-link'><a>" 
		                                    +data[i].messageCount+"条评论<a></span>");
								Comments.appendTo(metaDiv);
								//正文
								var mainText = $("<div class='list-content'>"
										+ delHtmlTag(data[i].mainText) + "</div>");
								var contentDiv=$("<div class='entry-content clearfix '></div>");
								contentDiv.appendTo(article);
								mainText.appendTo(contentDiv);
								var readDiv=$("<div class='read-more cl-effect-14'></div>");
								readDiv.appendTo(contentDiv);
								var link= $("<a href='single.html?id="+data[i].id+"'>详情</a>");
								link.appendTo(readDiv);
						};
				}
		});
		function doSubmitForm() {
		    var form = document.getElementById('ipt-content');
		   // showSearchResult(form.value);
		    window.location.href="category.html?kind="+form.value;
		}
		function setPageParam(data) {
			var nextPager,
				prePager;
			if(data.hasNextPage){
				nextPager =$("<li class='next'><a href=full-width.html?pageCount="+(data.currentPage+1)+" >下一页 &rarr;</a></li>");
			}else{
				nextPager =$("<li class='next disabled'><a >下一页 &rarr;</a></li>");
			}
			
			if(data.hasPreviousPage){
				prePager =$("<li class='previous'><a href=full-width.html?pageCount="+(data.currentPage-1)+" >&larr; 上一页</a></li>");
			}else{
				prePager =$("<li class='previous disabled'><a >&larr; 上一页</a></li>");
			}
			nextPager.appendTo($("#pager"));
			prePager.appendTo($("#pager"));
			
		}
	};
	
$(function(){
	getAllblogs();
});